class SkillDispatcher {
    constructor() {
        this.skillMap = new Map();
    }

    // 创建技能实例
    createSkill(skillId) {
        const SkillClass = SkillMapper[skillId];
        if (!SkillClass) {
            throw new Error(`未知的技能ID: ${skillId}`);
        }
        return new SkillClass();
    }

    // 注册技能到角色
    registerSkill(character, skillId) {
        const skill = this.createSkill(skillId);
        if (!this.skillMap.has(character.id)) {
            this.skillMap.set(character.id, new Map());
        }
        this.skillMap.get(character.id).set(skillId, skill);
    }

    // 使用技能
    useSkill(source, target, skillId, params = {}) {
        const characterSkills = this.skillMap.get(source.id);
        if (!characterSkills) {
            throw new Error(`角色${source.id}没有任何技能`);
        }

        const skill = characterSkills.get(skillId);
        if (!skill) {
            throw new Error(`角色${source.id}没有技能${skillId}`);
        }

        return skill.use(source, target, params);
    }

    // 更新所有技能冷却
    updateCooldowns(characterId) {
        const characterSkills = this.skillMap.get(characterId);
        if (characterSkills) {
            for (const skill of characterSkills.values()) {
                skill.updateCooldown();
            }
        }
    }
}

// 创建全局实例
const skillDispatcher = new SkillDispatcher();

